<%@page import="com.sun.mail.imap.protocol.Item"%>
<%@page import="study.top.mydb.items.ProductAllItem"%>
<%@page import="study.top.mydb.PaymentP"%>
<%@page import="study.top.mydb.PaymentInfo"%>
<%@page import="study.top.common.DBHandler"%>
<%@page import="study.top.mydb.items.WishListShowItem"%>
<%@page import="java.util.ArrayList"%>
<%@page import="study.top.mydb.WishListProduct"%>
<%@page import="study.top.common.PatternChecker"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ page session="true"%>
<%@ include file="dbcon.jsp"%>
<!DOCTYPE html>
<html lang="ko">
<%@ include file="topHead.jsp"%>
<!-- Top makes css file -->
<link rel="stylesheet" type="text/css" href="assets/css/topCommon.css" />
<body>
	<%@ include file="topcategory.jsp"%>
	<%
		db.connect();
		String[] lineseq = request.getParameterValues("chkbox1");
		if (lineseq == null) {
			out.print("<script type='text/javascript'>alert('선택된 상품이 없습니다.');</script>");
			return;
		}
		String usepoint = request.getParameter("usepoint");
		String zipcode = request.getParameter("zipcode");
		String total = request.getParameter("paysum");
		String point = request.getParameter("savepoint");
		String add1 = request.getParameter("add1");
		String add2 = request.getParameter("add2");

		int usepoint1 = Integer.parseInt(usepoint);
		int total1 = Integer.parseInt(total);
		int point1 = Integer.parseInt(point);
		int savepoint = point1 - usepoint1;
		/** 데이터 저장 */
		PaymentInfo p = new PaymentInfo();
		int info_seq = p.add(mem_seq, total1, savepoint, zipcode, add1,
				add2);

		PaymentP pay = new PaymentP();
		Product pro = new Product();
		WishListProduct wlp = new WishListProduct();
		for (int i = 0; i < lineseq.length; i++) {
			int seq1 = Integer.parseInt(lineseq[i]);
			ProductAllItem prolist = pro.show(seq1);
			WishListShowItem wlpshow_item = wlp.wishListMember(mem_seq,
					seq1);
			int seq2 = pay.add(info_seq, seq1, prolist.getDocid(),
					prolist.getTitle(), wlpshow_item.getQty(),
					prolist.getPrice_min(), prolist.getImgurl(),
					prolist.getReg_date(), prolist.getEdit_date());
			boolean result = wlp.PayOkDelete(mem_seq, seq1);
			if (!result) {
				out.print("<script type='text/javascript'>alert('삭제에 실패했습니다.');history.back();</script>");
				return;
			}
		}

		DBHandler.getInstance().disconnect();
	%>
	<div class="container top-margin-top-100">
		<h2 align="center">결제가 완료되었습니다.</h2>
		<div class="top-center">
			<a href="topmainpage.jsp"><button
					class="top-sm-text top-btn-size1 top-btn-custom">쇼핑 계속하기</button></a>
		</div>
	</div>
	<div class="top-hidden-xs">
		<%@include file="topBottom.jsp"%>
	</div>
</body>
</html>
